#include <iostream>

struct Big_alloc
{
    double data[1048576];
    // 1024 * 1024 = 1048576
};

int main(int argc, char const *argv[])
{
    Big_alloc *pt;

    try
    {
        std::cout << "Try to alloc Big_alloc memory!" << std::endl;
        std::cout << "One piece of Big_alloc is: " << sizeof(Big_alloc) << " bytes of data, " <<"equals " << (sizeof(Big_alloc) / 1024 / 1024) << " MB.";
        // in my machine, thise of Big_alloc 8MB
        pt = new Big_alloc[1000000];
        std::cout << "alloc success!" << std::endl;
        system("pause");
    }
    catch (std::bad_alloc &e)
    {
        std::cout << "caught bad_alloc exception" << std::endl;
        e.what();
    }
    catch (const std::exception &e)
    {
        std::cerr << e.what() << '\n';
    }
    return 0;
}
